# apparmor.d - Full set of apparmor profiles
# Copyright (C) 2022 Alexandre Pujol <alexandre@pujol.io>
# SPDX-License-Identifier: GPL-2.0-only

abi <abi/3.0>,

include <tunables/global>

@{exec_path} = /{usr/,}bin/login
profile login @{exec_path} flags=(attach_disconnected) {
  include <abstractions/base>
  include <abstractions/authentication>
  include <abstractions/consoles>
  include <abstractions/nameservice-strict>
  include <abstractions/wutmp>
  include <abstractions/dbus-strict>

  capability audit_write,
  capability chown,
  capability dac_read_search,
  capability fowner,
  capability fsetid,
  capability net_admin,
  capability setgid,
  capability setuid,
  capability sys_resource,
  capability sys_tty_config,

  network netlink raw,

  ptrace read,

  dbus send bus=system path=/org/freedesktop/login1
       interface=org.freedesktop.login1.*
       peer=(name=org.freedesktop.login1),

  @{exec_path} mr,

  /{usr/,}bin/{,z,ba,da}sh  rUx,

  /etc/default/locale r,
  @{etc_ro}/environment r,
  /etc/legal r,
  /etc/motd r,
  /etc/security/group.conf r,
  /etc/security/limits.conf r,
  @{etc_ro}/security/limits.d/{,*} r,
  /etc/security/pam_env.conf r,
  /etc/shells r,

  /var/log/btmp{,.[0-9]*} r,

  @{run}/dbus/system_bus_socket rw,
  @{run}/faillock/* rwk,
  @{run}/motd.dynamic{,.new} rw,
  @{run}/systemd/sessions/*.ref rw,

  owner @{PROC}/@{pid}/uid_map r,
  owner @{PROC}/@{pid}/loginuid rw,
        @{PROC}/1/limits r,

  owner @{user_cache_dirs}/motd.legal-displayed rw,

  /dev/tty[0-9]* rw,

  include if exists <local/login>
}
